package org.smartboot.socket.benchmark;

import org.smartboot.socket.Protocol;
import org.smartboot.socket.transport.AioSession;
import util.ByteExtUtil;

import java.nio.ByteBuffer;

/**
 * @author 三刀
 * @version V1.0 , 2018/11/23
 */
public class StringProtocol implements Protocol<String> {
    @Override
    public String decode(ByteBuffer readBuffer, AioSession<String> session) {
        byte[] rec_data = new byte[readBuffer.remaining()];
        readBuffer.get(rec_data);
        String bodydata = ByteExtUtil.bytesToHex(rec_data);
        System.out.println(session.getSessionID() + "：decode11：" + bodydata);
        return bodydata;
//        int remaining = readBuffer.remaining();
//        if (remaining < Integer.BYTES) {
//            return null;
//        }
//        readBuffer.mark();
//        int length = readBuffer.getInt();
//        if (length > readBuffer.remaining()) {
//            readBuffer.reset();
//            return null;
//        }
//        byte[] b = new byte[length];
//        readBuffer.get(b);
//        readBuffer.mark();
//        String s = new String(b);
//        System.out.println("服务端返回：" + s);
//        return s;
    }
}
